<!-- Web Upload Data Delete PHP File -->
<!-- Reveions History ...
	Rev 1.00 at 2015/06/08 by Max Yin:
		1. First time create
	Rev 1.01 at 2015/07/08 by Max Yin:
		1. 由標楷體, 改成新細明體
		2. 增加 FTP 上 Delete File 功能, 及是否要 delete 勾选
		3. 可删除 MySQL 上, 不同站别, 但相同版本及描述
	Reb 1.08 at 2015/12/08 by Max Yin,
		1. Web SMT upload 增加-回流焊的选项。(eric_liang)
		2. Web SMT upload/download, 由填入栏位改为下拉选单。(eric_liang)
		3. Web Upload/Downlaod 新增加 ESD 下拉选单。(jianwei_wang)
		4. 移除 ftp IP 的栏位输入, 由 Web 程式内定 FTP 路径。(Lucas)
		5. 修正重复上传, 却只有版本不对, 导致无法上传问题。(mingshen_feng)
		6. 修正若上传者, 若没有上传者名称, 会要求重新登入讯息。
-->
<html>
	<body background="pic/background_06.gif">
	<head>
		<font face="新細明體,time new roman,Arial">
		<meta charset="UTF-8">
	</head>
	<body>
		<center>
			<?php
				require_once('class_package/common.php');
				$tmp_pn			= "";
				$tmp_wsid		= "";
				$tmp_tpver		= "";
				$tmp_work_order	= "";	
				$tmp_line		= "";
				$tmp_panel		= "";
				$tmp_ftpip		= "";
				$db_select   = Sql_Download::sql_db;
				$db_table    = Sql_Download::sql_table;
				$table_name1 = Sql_Download::table_name1;	//webdl_pn
				$table_name2 = Sql_Download::table_name2;	//webdl_wsid
				$table_name3 = Sql_Download::table_name3;	//webdl_tpver
				$table_name4 = Sql_Download::table_name4;	//webdl_work_order
				$table_name5 = Sql_Download::table_name5;	//webdl_line
				$table_name6 = Sql_Download::table_name6;	//webdl_panel
				$table_name7 = Sql_Download::table_name7;	//webdl_panel
				$table_name8 = Sql_Download::table_name8;	//webdl_panel
				$table_name9 = Sql_Download::table_name9;	//webdl_panel
				$table_name10 = Sql_Download::table_name10;	//webdl_panel
				$table_name11 = Sql_Download::table_name11;	//webdl_panel
				$table_name12 = Sql_Download::table_name12;	//webdl_panel
				
				if ( @isset($_GET[pn]) && @isset($_GET[wsid]) && @isset($_GET[tpver]) && @isset($_GET[work_order]) && @isset($_GET[line]) && @isset($_GET[panel]) && @isset($_GET[ftpip]) && @isset($_GET[creator]) ) {
					@$tmp_pn			= $_GET[pn];
					@$tmp_wsid			= $_GET[wsid];
					@$tmp_tpver			= $_GET[tpver];
					@$tmp_work_order	= $_GET[work_order];	
					@$tmp_line			= $_GET[line];
					@$tmp_panel			= $_GET[panel];
					@$tmp_ftpip			= $_GET[ftpip];
					@$tmp_creator		= $_GET[creator];
					@$url				= $_GET[ftpip]; 
					@$webdl_count		= $_GET[webdl_count]; 	
																				
					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					if ( mysqli_connect_errno($conn) ) { 
						echo "<script>alert('MySql资料库连接失败,请联系开发人员,并查明原因...');history.go(-1);</script>";
					}
					mysqli_set_charset($conn,'set names utf8');
						
					date_default_timezone_set("Asia/Taipei");	// 定义时区为 亚洲/台北
					$each_date = date('Y-m-d G:i:s');			// 定义显示时间格式 2015-06-14 14:24:30					
					$sql_cmd = "UPDATE `$db_table` SET `$table_name11`=$webdl_count+1,`$table_name12`='$each_date' WHERE `$table_name1`='$tmp_pn' AND `$table_name2`='$tmp_wsid' AND `$table_name3`='$tmp_tpver' AND `$table_name4`='$tmp_work_order' AND `$table_name5`='$tmp_line' AND `$table_name6`='$tmp_panel'";				
					$result  = mysqli_query($conn,$sql_cmd);	// 透过 execute_query 对象实例完成添加
					$rows    = mysqli_affected_rows($conn);		// 获取刚刚更新资料笔数
					mysqli_close($conn);

					$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
					mysqli_set_charset($conn,'set names utf8');																						
					$sqll_cmd = "SELECT * FROM `$db_table` WHERE `$table_name1`='$tmp_pn' AND `$table_name2`='$tmp_wsid' AND `$table_name3`='$tmp_tpver' AND `$table_name4`='$tmp_work_order'";
					
					$res = mysqli_query($conn,$sqll_cmd);	// 透过 execute_query 对象实例完成查询
					
					$rows = mysqli_num_rows($res);		// 返回结果集中栏位的数量。
					
					//$myfile = fopen("D:/webdlfile.txt", "a") or die("Unable to open file!");						
					//$c="\r\n$tmp_work_order $tmp_pn $tmp_wsid $tmp_tpver $each_date $tmp_creator";
					//fwrite($myfile, $c);
					//fclose($myfile);//关闭该操作

					
					while ( $getArray = mysqli_fetch_array($res,MYSQLI_ASSOC) ) {					
						$put_ftpip  = $getArray['webdl_ftpip'];						
					}									
					mysqli_free_result($res);			
					mysqli_close($conn);
					
					echo "<script  type='text/javascript'>";
					echo "location.href='$put_ftpip'"; 
					echo "</script>";
					echo '<script language="javascript">history.go(-1);</script>';					
				} else {
					echo "<script language=javascript>alert('无此信息!');history.go(-1);</script>";
				}
			?>
		</center>
	</body>
</html>

